#define BE_DLL __declspec(dllexport)

#include <Engine.h>

Engine::Engine()
{
	Fps = 30;
}

Engine::~Engine()
{

}

void Engine::SetRoot( const char *dest )
{
	root = (char*)dest;
}

void Engine::LoadRoot( void )
{
	ifstream file( "game.ini", ios::in );

	if( file )
	{
		string dir;
		getline( file, dir );
		SetRoot( dir.c_str() );

		file.close();
	}
}

void Engine::Init( int Width, int Height )
{
	LoadRoot();

	SDL_Init( SDL_INIT_VIDEO );

	screen = SDL_SetVideoMode( Width, Height, 32, SDL_HWSURFACE | SDL_DOUBLEBUF );
}

bool Engine::GetContinue( Input *in )
{
	if( in->LastWindowEvent() == W_CLOSE )
		return false;

	if( in->LastKeyEvent() == SDLK_ESCAPE )
		return false;

	return true;
}

void Engine::Frame( Scene *scene )
{
	SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));

	scene->Render( screen );

	SDL_Flip( screen );
}

void Engine::SetFps( int FPS )
{
	if( FPS >= 5 )
		Fps = 1000 / FPS;
}

void Engine::Interrupt( void )
{
	SDL_Delay( Fps );
}

void Engine::Quit( void )
{
	if( screen )
		SDL_FreeSurface( screen );

	SDL_Quit();
}